#define _CRT_SECURE_NO_WARNINGS 1
//struct ListNode* FindKthToTail(struct ListNode* pListHead, int k) {
//	struct ListNode* fast, *slow;
//	fast = slow = pListHead;
//	while (k--)
//	{
//		if (fast == NULL)
//			return NULL;
//		fast = fast->next;
//	}
//	while (fast)
//	{
//		slow = slow->next;
//		fast = fast->next;
//	}
//	return slow;
//}

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdlib.h>
#include<assert.h>
#include<stdio.h>
typedef struct SList
{
	int data;
	struct SList* next;
}SList;

void SListprint(SList* phand)
{
	SList* cur = phand;
	while (cur)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");
}

SList* BuySList(int x)
{
	SList* newnode = (SList*)malloc(sizeof(SList));
	newnode->data = x;
	newnode->next = NULL;
	return newnode;
}
void SListpushAdd(SList** pphand, int val)
{
	SList* cur = *pphand;
	SList* newnode = BuySList(val);
	if (*pphand == NULL)
	{
		*pphand = newnode;
	}
	else
	{
		while (cur->next)
		{
			cur = cur->next;
		}
		cur->next = newnode;

	}
}
void SListpopadd(SList** pphand, int val)
{
	assert(*pphand);
	SList* newnode = BuySList(val);
	if (*pphand == NULL)
	{
		*pphand = newnode;
	}
	else
	{
		newnode->next = *pphand;
		*pphand = newnode;
	}
}

void SListposAfter(SList** pphand, int val)
{
	SList* prev = NULL;
	SList* cur = *pphand;
	SList* newnode = BuySList(10);
	if ((*pphand)->data == val)
	{
		newnode->next = *pphand;
		*pphand = newnode;
	}
	else
	{
		while (cur->data != val)
		{
			prev = cur;
			cur = cur->next;
		}
		newnode->data = 30;
		prev->next = newnode;
		newnode->next = cur;
	}
}
void SListposlate(SList** pphand, int val)
{
	assert(*pphand);
	SList* cur = *pphand;
	while (cur->data != val)
	{
		cur = cur->next;
	}
	SList* newnode = BuySList(val);
	newnode->next = cur->next;
	cur->next = newnode;
	newnode->data = 5;

}
void SListposDel(SList* phand, SList* pos)
{
	assert(phand);
	SList* cur = phand;
	while (cur->next != pos)
	{
		cur = cur->next;
	}
	cur->next = pos->next;
	free(pos);
	pos = NULL;
}
void SListfree(SList** pphand)
{
	SList* cur = *pphand;
	while (cur)
	{
		SList* next = cur->next;
		free(cur);
		cur = next;
	}
	*pphand = NULL;
}
void textSList1()
{
	SList *phand = NULL;
	SListpushAdd(&phand, 1);
	SListpushAdd(&phand, 2);
	SListpushAdd(&phand, 3);
	SListpushAdd(&phand, 4);
	SListpopadd(&phand, 1);
	//	SListpopadd(&phand, 2);
	//	SListpopadd(&phand, 3);
	//	SListpopadd(&phand, 4);
	//
	SListprint(phand);

}
void textSList2()
{
	/*SList *phand = NULL;
	SListpushAdd(&phand, 1);*/
	//SListpushAdd(&phand, 2);
	//SListpushAdd(&phand, 3);
	//SListpushAdd(&phand, 4);
	//SListposAfter(&phand,1);
	//SListposlate(&phand,1);

	//SListprint(phand);
}

int main()
{
	textSList1();
	/*textSList2();*/
	return 0;
}

//struct ListNode* removeElements(struct ListNode* head, int val){
//	if (head == NULL)
//		return NULL;
//	struct ListNode *prev, *cur;
//	prev = NULL; cur = head;
//	while (cur)
//	{
//		if (cur->val != val)
//		{
//			prev = cur;
//			cur = cur->next;
//		}
//		else
//		{
//			if (prev == NULL)
//			{
//				head = cur->next;
//				cur = cur->next;
//			}
//			else
//			{
//				prev->next = cur->next;
//				cur = cur->next;
//			}
//		}
//	}
//	if (prev == NULL)
//		return NULL;
//	return head;
//}